package baiguoyuan.kafka.simple;

public class InsertSort {
    public static void main(String[] args) {
        System.out.println("直接插入排序");
        int[] a = {10,9,8,7,7,7,6,6,6,5,4,3,2,1};
        insertSort(a);
        for (int i = 0; i < a.length; i++) {
            System.out.print(a[i] + " ");
        }

    }
    public static void insertSort(int[] a) {
        if (a.length == 0 || a.length == 1) {
            return;
        }
        for (int i = 1; i < a.length; i++) {
            int temp = a[i];
            int j = i - 1;
            for (; j >= 0 && a[j] > temp; j--) {
                a[j+1] = a[j];
            }
            a[j+1] = temp;
        }
    }
}